﻿/**************************************************************
*作者：Leon
*创建时间：2022/1/10 21:31:38
**************************************************************/

using SqlSugar;
using System.Linq.Expressions;

namespace MyBlog.IRepository;

public class BlogNewsRepository:BaseRepository<BlogNews>,IBlogNewsRepository
{
    public override async Task<List<BlogNews>> QueryAsync()
    {
        return await base.Context.Queryable<BlogNews>()
            .Mapper(c=>c.TypeInfo,c=>c.TypeId,c=>c.TypeInfo.Id)
            .Mapper(c=>c.WriterInfo,c=>c.WriterId,c=>c.WriterInfo.Id)
            .ToListAsync();
    }
    public override async Task<List<BlogNews>> QueryAsync(Expression<Func<BlogNews, bool>> func)
    {
        return await base.Context.Queryable<BlogNews>()
            .Where(func)
            .Mapper(c => c.TypeInfo, c => c.TypeId, c => c.TypeInfo.Id)
            .Mapper(c => c.WriterInfo, c => c.WriterId, c => c.WriterInfo.Id)
            .ToListAsync();
    }
    public override async Task<List<BlogNews>> QueryAsync(int page, int size, RefAsync<int> total)
    {
        return await base.Context.Queryable<BlogNews>()
            .Mapper(c => c.TypeInfo, c => c.TypeId, c => c.TypeInfo.Id)
            .Mapper(c => c.WriterInfo, c => c.WriterId, c => c.WriterInfo.Id)
            .ToPageListAsync(page, size, total);
    }
    public override async Task<List<BlogNews>> QueryAsync(Expression<Func<BlogNews, bool>> func, int page, int size, RefAsync<int> total)
    {
        return await base.Context.Queryable<BlogNews>()
            .Where(func)
            .Mapper(c => c.TypeInfo, c => c.TypeId, c => c.TypeInfo.Id)
            .Mapper(c => c.WriterInfo, c => c.WriterId, c => c.WriterInfo.Id)
            .ToPageListAsync(page,size,total);
            
    }
}
